<template>
  <view class="container">
    <AppointmentForm 
      @submit="handleSubmit"
      :warehouse-title="warehouseTitle"
      :warehouse-address="warehouseAddress"
      :submit-text="submitText"
      :initial-data="initialFormData"
    />
  </view>
</template>

<script>
import AppointmentForm from '@/components/AppointmentForm.vue'

export default {
  components: {
    AppointmentForm
  },
  data() {
    return {
      warehouseTitle: '',
      warehouseAddress: '',
      submitText: '',
      initialFormData: {
        // 可以从路由参数或API获取初始数据
        date: '',
        time: '',
        peopleIndex: 0,
        name: '',
        phone: '',
        email: '',
        remark: ''
      },
    }
  },
  onLoad(options) {
    // 处理路由参数，可以预填充表单数据
    if (options.warehouseId) {
      this.loadWarehouseInfo(options.warehouseId)
    }
  },
  methods: {
    async loadWarehouseInfo(warehouseId) {
      try {
        // 这里可以调用API获取仓库信息
        // const warehouseInfo = await API.warehouse.getDetail(warehouseId)
        // this.warehouseTitle = warehouseInfo.name
        // this.warehouseAddress = warehouseInfo.address
        console.log('加载仓库信息:', warehouseId)
      } catch (error) {
        console.error('加载仓库信息失败:', error)
      }
    },
    async handleSubmit(formData) {
      try {
        // 这里可以调用API提交预约数据
        console.log('预约详情数据:', formData)
        
        // 模拟API调用
        await new Promise(resolve => setTimeout(resolve, 1000))
        
        // 可以在这里添加实际的API调用
        // const result = await API.appointment.create(formData)
        
        return Promise.resolve()
      } catch (error) {
        console.error('预约提交失败:', error)
        return Promise.reject(error)
      }
    }
  }
}
</script>

<style scoped>
.container {
  min-height: 100vh;
}
</style>
